<?php

declare(strict_types=1);

namespace App\ContactMessageBatchSend\Controller\Dashboard;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Common\Middleware\DashboardAuthMiddleware;
use Base\Action\AbstractAction;
use Base\Request\ValidateSceneTrait;
use App\ContactMessageBatchSend\Logic\IndexLogic;

/**
 * 客户消息群发 - 消息列表.
 * @Controller
 */
class Index extends AbstractAction
{
    use ValidateSceneTrait;

    /**
     * @Inject
     * @var IndexLogic
     */
    private $indexLogin;

    /**
     * @Middlewares({
     *     @Middleware(DashboardAuthMiddleware::class),
     * })
     * @RequestMapping(path="/dashboard/contactMessageBatchSend/index", methods="GET")
     */
    public function handle(): array
    {
        ## 参数验证
        $this->validated($this->request->all());
        ## 接收参数
        $params = [
            'page' => $this->request->input('current', 1),
            'perPage' => $this->request->input('size', '10'),
        ];
        $params['page'] = intval($params['page']);
        $params['perPage'] = intval($params['perPage']);
        $batchTitle = $this->request->input('batchTitle', '');
        if (! empty($batchTitle)) {
            $params['batchTitle'] = $batchTitle;
        }
        $params['corpId'] = $this->request->input('userInfo.corp_id');
        $params['tenantId'] = $this->request->input('userInfo.tenant_id');
        return $this->indexLogin->handle($params, intval(user()['user_id']));
    }

    /**
     * 验证规则.
     *
     * @return array 响应数据
     */
    protected function rules(): array
    {
        return [
            'page' => 'integer|min:1',
            'perPage' => 'integer',
        ];
    }

    /**
     * 验证错误提示.
     * @return array 响应数据
     */
    protected function messages(): array
    {
        return [];
    }
}
